﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Campaign_Manager
{
    public class Settlement
    {
        #region Variables
        private string name;
        private Alignment alignment;
        private Settlement_Type type;
        private Settlement_Government government;

        private int population;

        private bool academic;
        private bool holy_site;
        private bool insular;
        private bool magically_attuned;
        private bool notorious;
        private bool pious;
        private bool prosperous;
        private bool racially_intolerant;
        private bool rumormongering_citizens;
        private bool strategic_location;
        private bool superstitious;
        private bool tourist_attraction;

        private bool anarchy;
        private bool cursed;
        private bool hunted;
        private bool impoverished;
        private bool plagued;

        private int[] minor_items;
        private int[] medium_items;
        private int[] major_items;

        private int[] diversity;
        #endregion

        public Settlement()
        {
            name = "Untitled";
            academic = false;
            holy_site = false;
            insular = false;
            magically_attuned = false;
            notorious = false;
            pious = false;
            prosperous = false;
            racially_intolerant = false;
            rumormongering_citizens = false;
            strategic_location = false;
            superstitious = false;
            tourist_attraction = false;

            anarchy = false;
            cursed = false;
            hunted = false;
            impoverished = false;
            plagued = false;

            population = 0;
            minor_items = new int[5];
            medium_items = new int[5];
            major_items = new int[5];
            diversity = new int[8];
            diversity[0] = 79;
            diversity[1] = 3;
            diversity[2] = 2;
            diversity[3] = 5;
            diversity[4] = 1;
            diversity[5] = 9;
            diversity[6] = 1;
            diversity[7] = 15;
            Random random = new Random();
            for (int i = 0; i < 4; i++)
            {
                minor_items[i] = random.Next(1, 5);
                medium_items[i] = random.Next(1, 5);
                major_items[i] = random.Next(1, 5);
            }
            minor_items[4] = random.Next(1, 7);
            medium_items[4] = random.Next(1, 7);
            major_items[4] = random.Next(1, 7);
        }

        #region Gets
        public int getHuman() { return diversity[0]; }
        public int getDwarf() { return diversity[1]; }
        public int getGnome() { return diversity[2]; }
        public int getElf() { return diversity[3]; }
        public int getHalfElf() { return diversity[4]; }
        public int getHalfling() { return diversity[5]; }
        public int getHalfOrc() { return diversity[6]; }
        public int getChildren() { return diversity[7]; }

        public string getName()
        {
            return name;
        }
        public int getCorruption()
        {
            int corruption = 0;
            if (type == Settlement_Type.Thorp)
                corruption -= 4;
            if (type == Settlement_Type.Hamlet)
                corruption -= 2;
            if (type == Settlement_Type.Village)
                corruption -= 1;
            if (type == Settlement_Type.Small_City)
                corruption += 1;
            if (type == Settlement_Type.Large_City)
                corruption += 2;
            if (type == Settlement_Type.Metropolis)
                corruption += 4;
            if (alignment == Alignment.Chaotic_Evil || alignment == Alignment.Lawful_Evil || alignment == Alignment.Neutral_Evil)
                corruption += 1;
            if (government == Settlement_Government.Magical)
                corruption -= 2;
            if (government == Settlement_Government.Overlord)
                corruption += 2;
            if (government == Settlement_Government.Secret_Syndicate)
                corruption += 2;
            if (holy_site)
                corruption -= 2;
            if (anarchy)
                corruption += 4;
            if (impoverished)
                corruption += 1;
            if (plagued)
                corruption -= 2;
            return corruption;
        }
        public int getCrime()
        {
            int crime = 0;
            if (type == Settlement_Type.Thorp)
                crime -= 4;
            if (type == Settlement_Type.Hamlet)
                crime -= 2;
            if (type == Settlement_Type.Village)
                crime -= 1;
            if (type == Settlement_Type.Small_City)
                crime += 1;
            if (type == Settlement_Type.Large_City)
                crime += 2;
            if (type == Settlement_Type.Metropolis)
                crime += 4;
            if (government == Settlement_Government.Overlord)
                crime -= 2;
            if (government == Settlement_Government.Secret_Syndicate)
                crime += 2;
            if (insular)
                crime -= 1;
            if (notorious)
                crime += 1;
            if (superstitious)
                crime -= 4;
            if (anarchy)
                crime += 4;
            if (impoverished)
                crime += 1;
            if (plagued)
                crime -= 2;
            if (alignment == Alignment.Chaotic_Evil || alignment == Alignment.Chaotic_Good || alignment == Alignment.Chaotic_Neutral)
                crime += 1;
            return crime;
        }
        public int getEconomy()
        {
            int economy = 0;
            if (type == Settlement_Type.Thorp)
                economy -= 4;
            if (type == Settlement_Type.Hamlet)
                economy -= 2;
            if (type == Settlement_Type.Village)
                economy -= 1;
            if (type == Settlement_Type.Small_City)
                economy += 1;
            if (type == Settlement_Type.Large_City)
                economy += 2;
            if (type == Settlement_Type.Metropolis)
                economy += 4;
            if (government == Settlement_Government.Secret_Syndicate)
                economy += 2;
            if (prosperous)
                economy += 1;
            if (strategic_location)
                economy += 1;
            if (tourist_attraction)
                economy += 1;
            if (anarchy)
                economy -= 4;
            if (hunted)
                economy -= 4;
            if (plagued)
                economy -= 2;
            return economy;
        }
        public int getLaw()
        {
            int law = 0;
            if (type == Settlement_Type.Thorp)
                law -= 4;
            if (type == Settlement_Type.Hamlet)
                law -= 2;
            if (type == Settlement_Type.Village)
                law -= 1;
            if (type == Settlement_Type.Small_City)
                law += 1;
            if (type == Settlement_Type.Large_City)
                law += 2;
            if (type == Settlement_Type.Metropolis)
                law += 4;
            if (government == Settlement_Government.Council)
                law -= 2;
            if (government == Settlement_Government.Overlord)
                law += 2;
            if (government == Settlement_Government.Secret_Syndicate)
                law -= 6;
            if (insular)
                law += 1;
            if (notorious)
                law -= 1;
            if (superstitious)
                law += 2;
            if (anarchy)
                law -= 6;
            if (hunted)
                law -= 4;
            if (plagued)
                law -= 2;
            if (alignment == Alignment.Lawful_Evil || alignment == Alignment.Lawful_Good || alignment == Alignment.Lawful_Neutral)
                law += 1;
            return law;
        }
        public int getLore()
        {
            int lore = 0;
            if (type == Settlement_Type.Thorp)
                lore -= 4;
            if (type == Settlement_Type.Hamlet)
                lore -= 2;
            if (type == Settlement_Type.Village)
                lore -= 1;
            if (type == Settlement_Type.Small_City)
                lore += 1;
            if (type == Settlement_Type.Large_City)
                lore += 2;
            if (type == Settlement_Type.Metropolis)
                lore += 4;
            if (government == Settlement_Government.Council)
                lore -= 2;
            if (government == Settlement_Government.Magical)
                lore += 2;
            if (alignment == Alignment.Chaotic_Neutral || alignment == Alignment.Lawful_Neutral)
                lore += 1;
            if (alignment == Alignment.Neutral_Neutral)
                lore += 2;
            if (academic)
                lore += 1;
            if (rumormongering_citizens)
                lore += 1;
            if (plagued)
                lore -= 2;
            return lore;
        }
        public int getSociety()
        {
            int society = 0;
            if (type == Settlement_Type.Thorp)
                society -= 4;
            if (type == Settlement_Type.Hamlet)
                society -= 2;
            if (type == Settlement_Type.Village)
                society -= 1;
            if (type == Settlement_Type.Small_City)
                society += 1;
            if (type == Settlement_Type.Large_City)
                society += 2;
            if (type == Settlement_Type.Metropolis)
                society += 4;
            if (alignment == Alignment.Neutral_Good || alignment == Alignment.Lawful_Good || alignment == Alignment.Chaotic_Good)
                society += 1;
            if (government == Settlement_Government.Council)
                society += 4;
            if (government == Settlement_Government.Magical)
                society -= 2;
            if (government == Settlement_Government.Overlord)
                society -= 2;
            if (rumormongering_citizens)
                society -= 1;
            if (superstitious)
                society += 2;
            if (anarchy)
                society -= 4;
            if (hunted)
                society -= 4;
            if (plagued)
                society -= 2;
            return society;
        }

        public int getMinorItems()
        {
            if (type == Settlement_Type.Thorp)
                return minor_items[0];
            if (type == Settlement_Type.Hamlet)
                return minor_items[4];
            if (type == Settlement_Type.Village)
                return minor_items[0] + minor_items[1];
            if (type == Settlement_Type.Small_Town || type == Settlement_Type.Large_Town)
                return minor_items[0] + minor_items[1] + minor_items[2];
            if (type == Settlement_Type.Small_City || type == Settlement_Type.Large_City)
                return minor_items[0] + minor_items[1] + minor_items[2] + minor_items[3];
            else
                return 999;
        }
        public int getMediumItems()
        {
            if (type == Settlement_Type.Thorp)
                return 0;
            if (type == Settlement_Type.Hamlet)
                return 0;
            if (type == Settlement_Type.Village)
                return medium_items[0];
            if (type == Settlement_Type.Small_Town)
                return medium_items[4];
            if (type == Settlement_Type.Large_Town)
                return medium_items[0] + medium_items[1];
            if (type == Settlement_Type.Small_City || type == Settlement_Type.Large_City)
                return medium_items[0] + medium_items[1] + medium_items[2];
            else
                return medium_items[0] + medium_items[1] + medium_items[2] + medium_items[3];
        }
        public int getMajorItems()
        {
            if (type == Settlement_Type.Thorp)
                return 0;
            if (type == Settlement_Type.Hamlet)
                return 0;
            if (type == Settlement_Type.Village)
                return 0;
            if (type == Settlement_Type.Small_Town)
                return 0;
            if (type == Settlement_Type.Large_Town)
                return medium_items[0];
            if (type == Settlement_Type.Small_City)
                return medium_items[4];
            if (type == Settlement_Type.Large_City)
                return medium_items[0] + medium_items[1];
            else
                return medium_items[0] + medium_items[1] + medium_items[2];
        }

        public int getBaseValue()
        {
            int baseValue = 0;
            switch (type)
            {
                case Settlement_Type.Thorp:
                    baseValue = 50;
                    break;
                case Settlement_Type.Hamlet:
                    baseValue = 200;
                    break;
                case Settlement_Type.Village:
                    baseValue = 500;
                    break;
                case Settlement_Type.Small_Town:
                    baseValue = 1000;
                    break;
                case Settlement_Type.Large_Town:
                    baseValue = 2000;
                    break;
                case Settlement_Type.Small_City:
                    baseValue = 4000;
                    break;
                case Settlement_Type.Large_City:
                    baseValue = 8000;
                    break;
                case Settlement_Type.Metropolis:
                    baseValue = 16000;
                    break;
            }
            int modifier = 100;
            if (magically_attuned)
                modifier += 20;
            if (notorious)
                modifier += 30;
            if (prosperous)
                modifier += 30;
            if (strategic_location)
                modifier += 10;
            if (tourist_attraction)
                modifier += 10;
            if (hunted)
                modifier -= 20;
            if (impoverished)
                modifier -= 50;
            if (plagued)
                modifier -= 20;
            baseValue = baseValue * modifier;
            return baseValue / 100;
        }
        public int getPurchaseLimit()
        {
            int purchase = 0;
            switch (type)
            {
                case Settlement_Type.Thorp:
                    purchase = 500;
                    break;
                case Settlement_Type.Hamlet:
                    purchase = 1000;
                    break;
                case Settlement_Type.Village:
                    purchase = 2500;
                    break;
                case Settlement_Type.Small_Town:
                    purchase = 5000;
                    break;
                case Settlement_Type.Large_Town:
                    purchase = 10000;
                    break;
                case Settlement_Type.Small_City:
                    purchase = 25000;
                    break;
                case Settlement_Type.Large_City:
                    purchase = 50000;
                    break;
                case Settlement_Type.Metropolis:
                    purchase = 100000;
                    break;
            }
            int modifier = 100;
            if (magically_attuned)
                modifier += 20;
            if (notorious)
                modifier += 50;
            if (prosperous)
                modifier += 50;
            if (impoverished)
                modifier -= 50;
            purchase = purchase * modifier;
            return purchase / 100;
        }

        public short getSpellcasterLevel()
        {
            short caster = 0;
            if (type == Settlement_Type.Thorp)
                caster = 1;
            if (type == Settlement_Type.Hamlet)
                caster = 2;
            if (type == Settlement_Type.Village)
                caster = 3;
            if (type == Settlement_Type.Small_Town)
                caster = 4;
            if (type == Settlement_Type.Large_Town)
                caster = 5;
            if (type == Settlement_Type.Small_City)
                caster = 6;
            if (type == Settlement_Type.Large_City)
                caster = 7;
            if (type == Settlement_Type.Metropolis)
                caster = 8;
            if (government == Settlement_Government.Magical)
                caster += 1;
            if (academic)
                caster += 1;
            if (holy_site)
                caster += 2;
            if (magically_attuned)
                caster += 2;
            if (superstitious)
                caster -= 2;
            return caster;
        }

        public int getDangerLevel()
        {
            int danger = 0;
            if (type == Settlement_Type.Thorp)
                danger = -10;
            if (type == Settlement_Type.Hamlet)
                danger = -5;
            if (type == Settlement_Type.Large_Town)
                danger = 5;
            if (type == Settlement_Type.Small_City)
                danger = 5;
            if (type == Settlement_Type.Large_City)
                danger = 10;
            if (type == Settlement_Type.Metropolis)
                danger = 10;
            if (notorious)
                danger += 10;
            if (anarchy)
                danger += 20;
            if (hunted)
                danger += 20;
            return danger;
        }

        public int getPopulation() { return population; }
        #endregion

        #region Sets
        public void setHuman(int value) { diversity[0] = value; }
        public void setDwarf(int value) { diversity[1] = value; }
        public void setGnome(int value) { diversity[2] = value; }
        public void setElf(int value) { diversity[3] = value; }
        public void setHalfElf(int value) { diversity[4] = value; }
        public void setHalfling(int value) { diversity[5] = value; }
        public void setHalfOrc(int value) { diversity[6] = value; }
        public void setChildren(int value) { diversity[7] = value; }

        public void setName(string Name)
        {
            this.name = Name;
        }
        public void setGovernment(int index)
        {
            switch (index)
            {
                case 0:
                    government = Settlement_Government.Autocracy;
                    break;
                case 1:
                    government = Settlement_Government.Council;
                    break;
                case 2:
                    government = Settlement_Government.Magical;
                    break;
                case 3:
                    government = Settlement_Government.Overlord;
                    break;
                case 4:
                    government = Settlement_Government.Secret_Syndicate;
                    break;
            }
        }
        public void setType(int index)
        {
            Random random = new Random();
            switch (index)
            {
                case 0:
                    type = Settlement_Type.Thorp;
                    population = random.Next(1, 21);
                    break;
                case 1:
                    type = Settlement_Type.Hamlet;
                    population = random.Next(21, 61);
                    break;
                case 2:
                    type = Settlement_Type.Village;
                    population = random.Next(61, 201);
                    break;
                case 3:
                    type = Settlement_Type.Small_Town;
                    population = random.Next(201, 2001);
                    break;
                case 4:
                    type = Settlement_Type.Large_Town;
                    population = random.Next(2001, 5001);
                    break;
                case 5:
                    type = Settlement_Type.Small_City;
                    population = random.Next(5001, 10001);
                    break;
                case 6:
                    type = Settlement_Type.Large_City;
                    population = random.Next(10001, 25001);
                    break;
                case 7:
                    type = Settlement_Type.Metropolis;
                    population = random.Next(25001, 100001);
                    break;
            }
        }
        public void setAlignment(int index)
        {
            switch (index)
            {
                case 0:
                    alignment = Alignment.Chaotic_Good;
                    break;
                case 1:
                    alignment = Alignment.Chaotic_Neutral;
                    break;
                case 2:
                    alignment = Alignment.Chaotic_Evil;
                    break;
                case 3:
                    alignment = Alignment.Neutral_Good;
                    break;
                case 4:
                    alignment = Alignment.Neutral_Neutral;
                    break;
                case 5:
                    alignment = Alignment.Neutral_Evil;
                    break;
                case 6:
                    alignment = Alignment.Lawful_Good;
                    break;
                case 7:
                    alignment = Alignment.Lawful_Neutral;
                    break;
                case 8:
                    alignment = Alignment.Lawful_Evil;
                    break;
            }
        }

        public void setAcademic(bool value) { academic = value; }
        public void setHolySite(bool value) { holy_site = value; }
        public void setInsular(bool value) { insular = value; }
        public void setMagicallyAttuned(bool value) { magically_attuned = value; }
        public void setNotorious(bool value) { notorious = value; }
        public void setPious(bool value) { pious = value; }
        public void setProsperous(bool value) { prosperous = value; }
        public void setRaciallyIntolerant(bool value) { racially_intolerant = value; }
        public void setRumormongeringCitizens(bool value) { rumormongering_citizens = value; }
        public void setStrategicLocation(bool value) { strategic_location = value; }
        public void setSuperstitious(bool value) { superstitious = value; }
        public void setTouristAttraction(bool value) { tourist_attraction = value; }

        public void setAnarchy(bool value) { anarchy = value; }
        public void setCursed(bool value) { cursed = value; }
        public void setHunted(bool value) { hunted = value; }
        public void setImpoverished(bool value) { impoverished = value; }
        public void setPlauged(bool value) { plagued = value; }

        public void setPopulation(int value) { population = value; }


        #endregion
    }
}
